package com.tedu.bill.demo4;

/**
 * Author：毕龙
 * Date: 2024/4/25 20:17
 * 接口的回调：先有接口的调用 再有接口的实现
 */
public class TestFindStudent1 {
    public static void main(String[] args) {
        //数组直接初始化
        Student[] students = {
                new Student("代琦", "男", 18, 89),
                new Student("子枭", "男", 20, 79),
                new Student("朱琳", "女", 21, 69),
                new Student("金草", "女", 22, 59),
                new Student("子荣", "男", 23, 99)
        };

        StudentFilter sf = new Student99();
        Student student = findStudent(students, sf);
        System.out.println(student);
        sf = new StudentAgeSex();
        student = findStudent(students, sf);
        System.out.println(student);
        //找个是代琦的学生
        sf = new StudentDaiQi();
        student = findStudent(students, sf);
        System.out.println(student);


    }

    //找个学生成绩是79
    public static Student findStudent(Student[] students,StudentFilter sf){
        for (int i = 0; i < students.length; i++) {
            //表示接口中的方法
            if(sf.filter(students[i])){
                return students[i];
            }
        }
        return null;
    }


}
